package com.three.iot.channel.impl.chinamobile;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.iot.model.v20180120.QueryDevicePropertyDataRequest;
import com.aliyuncs.iot.model.v20180120.QueryDevicePropertyDataResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.three.iot.commons.utils.DateUtil;

import java.util.Date;

/**
 * @author luiz
 * @Title: IotTest
 * @ProjectName iot-server
 * @Description: TODO
 * @date 2019-05-07 13:02
 */
public class DevicePropertyDataTest {
    public static void main(String[] args) {
        // 阿里云accessKey
        String accessKey = "LTAIM4zSiZd7rMzu";
        // 阿里云accessSecret
        String accessSecret = "LiKB95DldnjMSGhzrUIcFEqmysb864";
        try {
            DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Iot", "iot.cn-shanghai.aliyuncs.com");
        } catch (ClientException e) {
            e.printStackTrace();
        }
        IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
        //初始化SDK客户端
        DefaultAcsClient client = new DefaultAcsClient(profile);

        QueryDevicePropertyDataRequest request = new QueryDevicePropertyDataRequest();
      /*  request.setDeviceName("2019-001");
        request.setProductKey("a1BIyMhGr5p");*/
        request.setIotId("tjnuu56PJN8pEdaDu5O5000100");
        request.setIdentifier("INJ");
        Date startDate = new Date();
        startDate= DateUtil.getDayBefore(startDate);
        request.setStartTime(startDate.getTime());
        request.setEndTime(System.currentTimeMillis());
        request.setPageSize(100);
        request.setAsc(0);
        try {
            System.err.println("【阿里云】查询设备数据请求参数:" + JSONObject.toJSONString(request));
            QueryDevicePropertyDataResponse response = client.getAcsResponse(request);
            System.err.println("【阿里云】查询设备数据响应数据:" + JSONObject.toJSONString(response));

        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
